# @Author  : wangyiruo
# @Time    : 2024/12/5 18:38
# @Project：Python70_class
import json
from tools.handle_mysql import HandleMysql
from data.setting import my_db
from data.envi_data import EnviData
from loguru import logger


def pre_sql(sql_data):
    if sql_data is None:
        logger.info("没有要处理的sql数据")
        return
    logger.info("===========前置sql的处理=============")
    sql_data = json.loads(sql_data)
    logger.info(f"前置sql的表达式是{sql_data}")
    for k, v in sql_data.items():
        sql_result = HandleMysql(**my_db).query_data(v)  # 得到的是字典数据
        for i, j in sql_result.items():
            setattr(EnviData, i, j)
    logger.info(f"结果设置为环境变量后属性为:{EnviData.__dict__}")


if __name__ == '__main__':
    sql_data = """{"mobile_code":
    "select mobile_code,user_phone from tz_sms_log where user_phone='13422337768' order by rec_date desc limit 1;"}"""
    pre_sql(sql_data)
